package com.example.android.plugin.framework.util;

import java.lang.reflect.Field;

import android.content.Context;

public class Utils {

	/**
	 * 改掉指定ClassLoader的爹
	 * 
	 * @param context
	 * @param parent
	 * @return
	 * @throws NoSuchFieldException
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 */
	public static ClassLoader changeClassLoaderParent(Context context,
			ClassLoader parent) throws NoSuchFieldException,
			IllegalAccessException, IllegalArgumentException {
		ClassLoader loader = context.getClassLoader();
		Field field = ClassLoader.class.getDeclaredField("parent");
		field.setAccessible(true);
		field.set(loader, parent);
		return loader;
	}
}
